import os, subprocess, sys
from posixpath import join
from os import path

if __name__ == '__main__':
    src = sys.argv[1]
    trg = sys.argv[2]
    seeds = range(0, 10)
    # seeds = [0]
    exp_name = 'Feb24_direct_zhde'
    exp_id = src + '-' + trg + '_ggdict'
    exp_path = path.join('dumped', exp_name, exp_id)
    if not path.exists(exp_path):
        os.makedirs(exp_path)
    norm_ops = ['unit', 'center'] * 5 + ['unit']
    log_file_path = path.join(exp_path , "vecmap_log.txt")
    for i in seeds:
        subprocess.run([
            "python3", "vecmap_main_modularized.py", 
            # "dumped/Seg04_lowcutoff/vi-en/vectors-vi.txt", "dumped/Sep06_stepcutoff/vi-en/vectors-en.txt",
            "data/wiki." + src + ".vec", "data/wiki." + trg + ".vec", 
            path.join(exp_path, src + ".mapped_emb.txt"), path.join(exp_path, trg + ".mapped_emb.txt"),
            "--unsupervised",
            # "--orthogonal",
            "--verbose",
            # "--validation", '../pivot_based_zhde/' + src + '-' + trg + ".0-5000_baidu.txt",
<<<<<<< HEAD
            "--validation", '../pivot_based_zhde/' + src + '-' + trg + ".0-5000.gg.txt",
=======
            "--validation", '../pivot_based_zhde/' + src + '-' + trg + ".sase.txt",
>>>>>>> 2eae875b18e60d8a16facaae8767ac437cafefc2
            # "--batch_size", "4000",
            # "--vocabulary_cutoff", "20000",
            "--log", log_file_path,
            "--seed", str(i),
            "--cuda",
            "--normalize", *norm_ops,
        ])
        file_mode = 'a' if os.path.exists(log_file_path) else 'w'
        with open(log_file_path, file_mode) as logfile:
            subprocess.run([
                "python3","eval_translation.py",
                path.join(exp_path, src + ".mapped_emb.txt"),
                path.join(exp_path, trg + ".mapped_emb.txt"),
                "-d", path.join('../pivot_based_zhde/' , src + '-' + trg + ".sase.txt"),
                "--cuda",
                "--seed", str(i),
                "--retrieval", "csls",
            ], stdout=logfile)